#include "Precomp.h"
#include "AnimatedSprite.h"
#include "Map.h"

AnimatedSprite::AnimatedSprite(const SQChar* path, const AnimationProfile& animationProfile, float speed)
:SpriteBased(Entity::ANIMATED,path),animProfile(animationProfile),speed(speed),frame(0)
{
	currentMap->addAnimatedSprite(this);
	frameCount=animationProfile.getFrameCount();
	sf::IntRect intRect=animProfile.getFrame(0);
	size.x=(float)(intRect.GetWidth());
	size.y=(float)(intRect.GetHeight());
}

void AnimatedSprite::animate()
{
	frame+=speed;
	if(frame+1>frameCount)
		frame=0;
	shape_impl.SetSubRect(animProfile.getFrame((int)frame));
}